knitr::opts_chunk$set(echo = TRUE)
library(devtools)
## Loading required package: usethis
library(rprojroot)
load_all()
## ℹ Loading DSPWorkflow
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## Loading required package: Biobase
## Loading required package: BiocGenerics
## 
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
## 
##     anyDuplicated, append, as.data.frame, basename, cbind, colnames,
##     dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
##     grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
##     order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
##     rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
##     union, unique, unsplit, which.max, which.min
## Welcome to Bioconductor
## 
##     Vignettes contain introductory material; view with
##     'browseVignettes()'. To cite Bioconductor, see
##     'citation("Biobase")', and for packages 'citation("pkgname")'.
## Loading required package: cowplot
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:Biobase':
## 
##     combine
## The following objects are masked from 'package:BiocGenerics':
## 
##     combine, intersect, setdiff, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: GeomxTools
## Loading required package: NanoStringNCTools
## Loading required package: S4Vectors
## Loading required package: stats4
## 
## Attaching package: 'S4Vectors'
## The following objects are masked from 'package:dplyr':
## 
##     first, rename
## The following objects are masked from 'package:base':
## 
##     expand.grid, I, unname
## Loading required package: ggplot2
## 
## Attaching package: 'NanoStringNCTools'
## The following object is masked from 'package:dplyr':
## 
##     groups
## Loading required package: ggforce
## Loading required package: gridExtra
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
## The following object is masked from 'package:Biobase':
## 
##     combine
## The following object is masked from 'package:BiocGenerics':
## 
##     combine
## Loading required package: grid
## Loading required package: gtable
## Loading required package: knitr
## Loading required package: patchwork
## 
## Attaching package: 'patchwork'
## The following object is masked from 'package:cowplot':
## 
##     align_plots
## Loading required package: reshape2
## Loading required package: Rtsne
## Loading required package: scales
## Loading required package: SpatialDecon
## Loading required package: tibble
## Loading required package: tidyr
## 
## Attaching package: 'tidyr'
## The following object is masked from 'package:reshape2':
## 
##     smiths
## The following object is masked from 'package:S4Vectors':
## 
##     expand
## Loading required package: umap
## Loading required package: magrittr
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:tidyr':
## 
##     extract
## Loading required package: ComplexHeatmap
## ========================================
## ComplexHeatmap version 2.10.0
## Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
## Github page: https://github.com/jokergoo/ComplexHeatmap
## Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
## 
## If you use it in published research, please cite:
## Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
##   genomic data. Bioinformatics 2016.
## 
## The new InteractiveComplexHeatmap package can directly export static 
## complex heatmaps into an interactive Shiny app with zero effort. Have a try!
## 
## This message can be suppressed by:
##   suppressPackageStartupMessages(library(ComplexHeatmap))
## ========================================
root <- rprojroot::find_package_root_file()

knitr::opts_chunk$set(fig.width=12, fig.height=8, out.width = '100%') 
knitr::opts_knit$set(root.dir = root)

R Markdown

This runs the DSPworkflow package to completion using the Human Colon Dataset:

1. Study Design:

  # Set paths for downloading dcc files
  downloads.path <- test_path("fixtures/Human_Colon/downloaded/")
  tar.file.name <- "colon_dccs.tar.gz"
  full.tar.path <- paste0(downloads.path,tar.file.name)
  
  # Check if dcc files were previously downloaded
  if (!file.exists(full.tar.path)) {
    
    # Download dcc files and place in data folder
    data.url <- "http://hpc.nih.gov/~CCBR/DSPWorkflow/colon_dccs.tar.gz"
    download.file(data.url, full.tar.path)
    untar(full.tar.path, exdir = downloads.path)
  }
  
  dcc.files <- dir(
    file.path(
      downloads.path,
      "dccs"
    ),
    pattern = ".dcc$",
    full.names = TRUE,
    recursive = TRUE
  )
    
  pkc.files <-
    test_path("fixtures/Human_Colon/Hs_R_NGS_WTA_v1.0.pkc")
  pheno.data.file <-
    test_path("fixtures/Human_Colon/colon_soa_annotation.xlsx")
  
  sdesign.list <- studyDesign(dcc.files = dcc.files, 
                                pkc.files = pkc.files,
                                pheno.data.file = pheno.data.file,
                                pheno.data.sheet = "SegmentProperties",
                                pheno.data.dcc.col.name = "Sample_ID",
                                protocol.data.col.names = c("aoi", "roi"),
                                experiment.data.col.names = c("panel"),
                                slide.name.col = "slide name", 
                                class.col = "class", 
                                region.col = "region", 
                                segment.col = "segment",
                                area.col = "area",
                                nuclei.col = "nuclei")
## Warning in readNanoStringGeoMxSet(dccFiles = dcc.files, pkcFiles = pkc.files, :
## Annotations missing for the following: DSP-1012300100510-H-A01.dcc, These will
## be excluded from the GeoMxSet object.
## Warning in studyDesign(dcc.files = dcc.files, pkc.files = pkc.files, pheno.data.file = pheno.data.file, : nuclei is not found in the annotation and will not be considered
  # For creating fixture RDS
  create.rds <- TRUE
  if(create.rds) {
    study.design.human.colon <- sdesign.list$object
    saveRDS(study.design.human.colon, file = "tests/testthat/fixtures/Human_Colon/studyDesignHumanColon.RDS")
  }
  
  print(sdesign.list$sankey.plot)

  print("Created GeoMx Object\n\n")
## [1] "Created GeoMx Object\n\n"
  pData(sdesign.list$object)[,c("slide_name","class","segment")]  
##                             slide_name class           segment
## DSP-1012300100510-H-A02.dcc    Male_50 colon            PanCK+
## DSP-1012300100510-H-A03.dcc    Male_50 colon            PanCK-
## DSP-1012300100510-H-A04.dcc    Male_50 colon            PanCK+
## DSP-1012300100510-H-A05.dcc    Male_50 colon            PanCK-
## DSP-1012300100510-H-A06.dcc    Male_50 colon            PanCK+
## DSP-1012300100510-H-A07.dcc    Male_50 colon            PanCK-
## DSP-1012300100510-H-A08.dcc    Male_50 colon            PanCK+
## DSP-1012300100510-H-A09.dcc    Male_50 colon            PanCK-
## DSP-1012300100510-H-A10.dcc    Male_50 colon            PanCK+
## DSP-1012300100510-H-A11.dcc    Male_50 colon            PanCK-
## DSP-1012300100510-H-A12.dcc    Male_50 colon            PanCK+
## DSP-1012300100510-H-B01.dcc    Male_50 colon            PanCK-
## DSP-1012300100510-H-B02.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-B03.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-B04.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-B05.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-B06.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-B07.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-B08.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-B09.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-B10.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-B11.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-B12.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-C01.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-C02.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-C03.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-C04.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-C05.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-C06.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-C07.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-C08.dcc    Male_50 colon             HT-5+
## DSP-1012300100510-H-C09.dcc    Male_50 colon             HT-5+
## DSP-1012300100510-H-C10.dcc    Male_50 colon             HT-5+
## DSP-1012300100510-H-C11.dcc    Male_50 colon             HT-5+
## DSP-1012300100510-H-C12.dcc    Male_50 colon             HT-5+
## DSP-1012300100510-H-D01.dcc    Male_50 colon             HT-5+
## DSP-1012300100510-H-D02.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-D03.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-D04.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-D05.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-D06.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-D07.dcc    Male_50 colon Geometric Segment
## DSP-1012300100510-H-D08.dcc    Male_63 colon            PanCK+
## DSP-1012300100510-H-D09.dcc    Male_63 colon            PanCK-
## DSP-1012300100510-H-D10.dcc    Male_63 colon            PanCK+
## DSP-1012300100510-H-D11.dcc    Male_63 colon            PanCK-
## DSP-1012300100510-H-D12.dcc    Male_63 colon            PanCK+
## DSP-1012300100510-H-E01.dcc    Male_63 colon            PanCK-
## DSP-1012300100510-H-E02.dcc    Male_63 colon            PanCK+
## DSP-1012300100510-H-E03.dcc    Male_63 colon            PanCK-
## DSP-1012300100510-H-E04.dcc    Male_63 colon            PanCK+
## DSP-1012300100510-H-E05.dcc    Male_63 colon            PanCK-
## DSP-1012300100510-H-E06.dcc    Male_63 colon            PanCK+
## DSP-1012300100510-H-E07.dcc    Male_63 colon            PanCK-
## DSP-1012300100510-H-E08.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-E09.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-E10.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-E11.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-E12.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F01.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F02.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F03.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F04.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F05.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F06.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F07.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F08.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F09.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F10.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F11.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-F12.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-G01.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-G02.dcc    Male_63 colon             HT-5+
## DSP-1012300100510-H-G03.dcc    Male_63 colon             HT-5+
## DSP-1012300100510-H-G04.dcc    Male_63 colon             HT-5+
## DSP-1012300100510-H-G05.dcc    Male_63 colon             HT-5+
## DSP-1012300100510-H-G06.dcc    Male_63 colon             HT-5+
## DSP-1012300100510-H-G07.dcc    Male_63 colon             HT-5+
## DSP-1012300100510-H-G08.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-G09.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-G10.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-G11.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-G12.dcc    Male_63 colon Geometric Segment
## DSP-1012300100510-H-H01.dcc    Male_50 colon Geometric Segment
## DSP-1012550000101-H-A02.dcc  Female_73 colon            PanCK+
## DSP-1012550000101-H-A03.dcc  Female_73 colon            PanCK-
## DSP-1012550000101-H-A04.dcc  Female_73 colon            PanCK+
## DSP-1012550000101-H-A05.dcc  Female_73 colon            PanCK-
## DSP-1012550000101-H-A06.dcc  Female_73 colon            PanCK+
## DSP-1012550000101-H-A07.dcc  Female_73 colon            PanCK-
## DSP-1012550000101-H-A08.dcc  Female_73 colon            PanCK+
## DSP-1012550000101-H-A09.dcc  Female_73 colon            PanCK-
## DSP-1012550000101-H-A10.dcc  Female_73 colon            PanCK+
## DSP-1012550000101-H-A11.dcc  Female_73 colon            PanCK-
## DSP-1012550000101-H-A12.dcc  Female_73 colon            PanCK+
## DSP-1012550000101-H-B01.dcc  Female_73 colon            PanCK-
## DSP-1012550000101-H-B02.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-B03.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-B04.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-B05.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-B06.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-B07.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-B08.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-B09.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-B10.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-B11.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-B12.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-C01.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-C02.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-C03.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-C04.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-C05.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-C06.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-C07.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-C08.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-C09.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-C10.dcc  Female_73 colon          segment1
## DSP-1012550000101-H-C11.dcc  Female_73 colon          segment1
## DSP-1012550000101-H-C12.dcc  Female_73 colon          segment1
## DSP-1012550000101-H-D01.dcc  Female_73 colon          segment1
## DSP-1012550000101-H-D02.dcc  Female_73 colon          segment1
## DSP-1012550000101-H-D03.dcc  Female_73 colon          segment1
## DSP-1012550000101-H-D04.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-D05.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-D06.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-D07.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-D08.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-D09.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-D10.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-D11.dcc  Female_73 colon          Full ROI
## DSP-1012550000101-H-D12.dcc  Female_39 colon            PanCK+
## DSP-1012550000101-H-E01.dcc  Female_39 colon            PanCK-
## DSP-1012550000101-H-E02.dcc  Female_39 colon            PanCK+
## DSP-1012550000101-H-E03.dcc  Female_39 colon            PanCK-
## DSP-1012550000101-H-E04.dcc  Female_39 colon            PanCK+
## DSP-1012550000101-H-E05.dcc  Female_39 colon            PanCK-
## DSP-1012550000101-H-E06.dcc  Female_39 colon            PanCK+
## DSP-1012550000101-H-E07.dcc  Female_39 colon            PanCK-
## DSP-1012550000101-H-E08.dcc  Female_39 colon            PanCK+
## DSP-1012550000101-H-E09.dcc  Female_39 colon            PanCK-
## DSP-1012550000101-H-E10.dcc  Female_39 colon            PanCK+
## DSP-1012550000101-H-E11.dcc  Female_39 colon            PanCK-
## DSP-1012550000101-H-E12.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F01.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F02.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F03.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F04.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F05.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F06.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F07.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F08.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F09.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F10.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F11.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-F12.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-G01.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-G02.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-G03.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-G04.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-G05.dcc  Female_39 colon          segment1
## DSP-1012550000101-H-G06.dcc  Female_39 colon          segment1
## DSP-1012550000101-H-G07.dcc  Female_39 colon          segment1
## DSP-1012550000101-H-G08.dcc  Female_39 colon          segment1
## DSP-1012550000101-H-G09.dcc  Female_39 colon          segment1
## DSP-1012550000101-H-G10.dcc  Female_39 colon          segment1
## DSP-1012550000101-H-G11.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-G12.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-H01.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-H02.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-H03.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-H04.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-H05.dcc  Female_39 colon          Full ROI
## DSP-1012550000101-H-H06.dcc    Male_63 colon          Full ROI

2. QC Preprocessing:

    qc.output <-  qcProc(object = sdesign.list$object,
                        min.segment.reads = 1000,
                        percent.trimmed = 80,
                        percent.stitched = 80,
                        percent.aligned = 80,
                        percent.saturation = 50,
                        min.negative.count = 1,  
                        max.ntc.count = 1000,     
                        min.nuclei = 200,         
                        min.area = 1000,
                        print.plots = TRUE)
## Warning in qcProc(object = sdesign.list$object, min.segment.reads = 1000, : nuclei not found in the annotation, min.nuclei will not be considered

## 
## 
## Table: Summary for the NTC values
## 
## |NTC Count | # of Segments|
## |:---------|-------------:|
## |285       |           173|
## 
## 
## Table: QC Summary for each Segment
## 
## |              | Pass| Warning|
## |:-------------|----:|-------:|
## |LowReads      |  173|       0|
## |LowTrimmed    |  173|       0|
## |LowStitched   |  172|       1|
## |LowAligned    |  169|       4|
## |LowSaturation |  172|       1|
## |LowNegatives  |  173|       0|
## |HighNTC       |  173|       0|
## |LowArea       |  173|       0|
## |TOTAL FLAGS   |  168|       5|
## 
## 
## Table: Summary for Segment QC Removal
## 
## |         | # Before Removal| # After Removal|
## |:--------|----------------:|---------------:|
## |Features |            18815|           18815|
## |Samples  |              173|             168|
## 
## 
## Table: Summary for Probe QC Calls (Grubb's Outlier Test)
## 
## | Passed| Global| Local|
## |------:|------:|-----:|
## |  18797|      0|    18|
## 
## 
## Table: Summary for Probe QC Removal
## 
## |         | # Before Collapsing| # After Collapsing|
## |:--------|-------------------:|------------------:|
## |Features |               18815|              18815|
## |Samples  |                 168|                168|
## 
## 
## Table: Summary for Gene-level Counts
## 
## |         | # Before Collapsing| # After Collapsing|
## |:--------|-------------------:|------------------:|
## |Features |               18815|              18677|
## |Samples  |                 168|                168|
    print(qc.output$segments.qc)
## NULL
  create.rds <- TRUE
  if(create.rds) {
    qc.human.colon<- qc.output$object
    saveRDS(qc.human.colon, file = "tests/testthat/fixtures/Human_Colon/qcHumanColon.RDS")
  }

3. Filtering:

    goi <- c("PDCD1", "CD274", "IFNG", "CD8A", "CD68", "EPCAM", "KRT18", "NPHS1", "NPHS2", "CALB1", "CLDN8")
    
    filtering.output <- filtering(object = qc.output$object,
                            loq.cutoff = 2, 
                            loq.min = 2, 
                            cut.segment = .05, 
                            goi = goi)
    
    print(filtering.output$`stacked.bar.plot`)

    print(filtering.output$`tab`)
## 
## 
## |       | colon|
## |:------|-----:|
## |<1%    |     0|
## |1-5%   |    13|
## |5-10%  |    22|
## |10-15% |    30|
## |>15%   |   103|
    print(filtering.output$`sankey.plot`)

    print(filtering.output$`genes.detected.plot`)

  create.rds <- TRUE
  if(create.rds) {
    filtering.human.colon <- filtering.output$object
    saveRDS(filtering.human.colon, file = "tests/testthat/fixtures/Human_Colon/filteringHumanColon.RDS")
  }

4. Normalization:

    q3.normalization.output <- geomxNorm(
                                  object = filtering.output$object, 
                                  norm = "q3")
## Using Segment, Annotation as id variables
## No id variables; using all as measure variables
## No id variables; using all as measure variables
    print(q3.normalization.output$multi.plot)

    print(q3.normalization.output$boxplot.raw)

    print(q3.normalization.output$boxplot.norm)

    neg.normalization.output <- geomxNorm(
                                  object = filtering.output$object, 
                                  norm = "neg")
## Using Segment, Annotation as id variables
## No id variables; using all as measure variables
## No id variables; using all as measure variables
    print(neg.normalization.output$multi.plot)

    print(neg.normalization.output$boxplot.raw)

    print(neg.normalization.output$boxplot.norm)

    create.rds <- TRUE
    if(create.rds) {
      q3.normalization.human.colon <- q3.normalization.output$object
      saveRDS(q3.normalization.human.colon, file = "tests/testthat/fixtures/Human_Colon/q3normalizationHumanColon.RDS")
      neg.normalization.human.colon <- neg.normalization.output$object
      saveRDS(neg.normalization.human.colon, file = "tests/testthat/fixtures/Human_Colon/negnormalizationHumanColon.RDS")
      
    }    

5. Unsupervised Analysis:

    #Test Unsupervised Analysis:
    unsupervised.output <- dimReduct(object = q3.normalization.output$object,
                        point.size = 3,
                        point.alpha = 1,
                        color.variable1 = "region",
                        shape.variable = "class"
    )
## using q_norm in the dimensional reductions
## adding in the phenoData PCA, tSNE, and UMAP coordinates
    print(unsupervised.output$plot$PCA)

    print(unsupervised.output$plot$tSNE)

    print(unsupervised.output$plot$UMAP)

6. Clustering high CV Genes and Heatmap:

    heatmap.output <- heatMap(object = unsupervised.output$object, 
                        ngenes = 200, 
                        scale.by.row.or.col = "row", 
                        show.rownames = FALSE, 
                        show.colnames = FALSE, 
                        clustering.method = "average", 
                        cluster.rows = TRUE, 
                        cluster.cols = TRUE,
                        clustering.distance.rows = "correlation", 
                        clustering.distance.cols = "correlation", 
                        annotation.row = NA, 
                        annotation.col = c("class", "segment", "region"), 
                        breaks.by.values = seq(-3, 3, 0.05), 
                        heatmap.color = colorRampPalette(c("blue", "white", "red"))(120), 
                        norm.method = "quant")
## Warning: It not suggested to both set `scale` and `breaks`. It makes the
## function confused.
    print(heatmap.output$plot)

7. Differential Expression Analysis:

    goi <- c("CD274", "CD8A", "CD68", "EPCAM",
             "KRT18", "JCHAIN")
    
    object <- q3.normalization.output$object
    object <- object[goi,]
    Gene <- Subset <- NULL
    
    #First analysis:
    reslist.1 <- diffExpr(object = object, 
                          analysis.type = "Within Groups", 
                          region.col = "segment", 
                          regions = c("PanCK+", "PanCK-"), 
                          group.col = "region", 
                          groups = c("Lamina"), 
                          n.cores = 4)
## At least one of the regions within the Region Column was not selected
##             and is excluded: Geometric Segment, HT-5+, Full ROI, segment1
## Running Within Group Analysis between Regions
## Number of regions in group Lamina: 2
    grid.draw(reslist.1$sample_table)
    grid.newpage()
    grid.draw(reslist.1$summary_table)
    
    lfc_col1 <- colnames(reslist.1$result)[grepl("logFC",colnames(reslist.1$result))]
    pval_col1 <- colnames(reslist.1$result)[grepl("_pval",colnames(reslist.1$result))]
    
    lfc.1 <- reslist.1$result %>% 
              dplyr::filter(Gene == "JCHAIN" & Subset == "Lamina") %>% 
              select(all_of(lfc_col1)) %>% 
              as.numeric()
    pval.1 <- reslist.1$result %>% 
              dplyr::filter(Gene == "JCHAIN" & Subset == "Lamina") %>% 
              select(all_of(pval_col1)) %>% 
              as.numeric()
    
    cat(paste0("\n\nvalue of JCHAIN Fold Change is:", lfc.1))
## 
## 
## value of JCHAIN Fold Change is:-4.53
    cat("expected value is -2.014")
## expected value is -2.014
    cat(paste0("\nvalue of JCHAIN pval is:",pval.1))
## 
## value of JCHAIN pval is:0.0677
    cat("expected value is 0.0274")
## expected value is 0.0274
    #Second analysis:
    reslist.2 <- diffExpr(object = object, 
                          analysis.type = "Between Groups", 
                          region.col = "class", 
                          regions = c("colon"), 
                          group.col = "region", 
                          groups = c("Lymphoid", "Lamina"), 
                          n.cores = 4)
## At least one of the groups within the Group Column was not selected and
##             is excluded: Epithelium, Circ Muscle, Long Muscle, Mus Muc, Paneth, Vessels, Conn Tiss, Ent Cells
## Running Between Group Analysis for Regions
## Number of groups in region colon: 2
    grid.draw(reslist.2$sample_table)
    grid.newpage()
    grid.draw(reslist.2$summary_table)
    
    lfc_col2 <- colnames(reslist.2$result)[grepl("logFC",colnames(reslist.2$result))]
    pval_col2 <- colnames(reslist.2$result)[grepl("_pval",colnames(reslist.2$result))]
    
    lfc.2 <- reslist.2$result %>% 
              dplyr::filter(Gene == "JCHAIN" & Subset == "colon") %>% 
              select(all_of(lfc_col2)) %>% 
              as.numeric()
    pval.2 <- reslist.2$result %>% 
              dplyr::filter(Gene == "JCHAIN" & Subset == "colon") %>% 
              select(all_of(pval_col2)) %>% 
              as.numeric()
    
    cat(paste0("\n\nvalue of JCHAIN Fold Change is:", lfc.2))
## 
## 
## value of JCHAIN Fold Change is:-4.548
    cat("expected value is negative")
## expected value is negative
    cat(paste0("\nvalue of JCHAIN pval is:",pval.2))
## 
## value of JCHAIN pval is:4.49e-08
    cat("expected value is significant")
## expected value is significant

8. Volcano Plot

#This part is run on NIDAP.

9. Violin Plot

    genes <- c("CD274", "CD8A", "CD68", "EPCAM",
             "KRT18", "JCHAIN")
    
    violin.plot.test <- violinPlot(object = q3.normalization.output$object, 
                                        expr.type = "q_norm", 
                                        genes = genes,
                                        group = "region",
                                        facet.by = "segment")
## [1] " not found and will not be displayed"
## Warning: Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
    grid.arrange(violin.plot.test)

10. Spatial Deconvolution:

    ref.mtx = read.csv(test_path("fixtures", "sample_spatial_deconv_mtx.csv"), 
                       row.names=1, check.names=FALSE)
    rownames(ref.mtx) = sample(rownames(q3.normalization.output$object), size = 1500, replace = FALSE)
    ref.annot = read.csv(test_path("fixtures", "ref_annot.csv"))
    
    spatial.output <- spatialDeconvolution(object = q3.normalization.output$object, 
                                           expr.type = "q_norm", 
                                           ref.mtx = ref.mtx, 
                                           prof.mtx = NULL, 
                                           use.custom.prof.mtx = TRUE,
                                           ref.annot = ref.annot, 
                                           cell.id.col = "CellID", 
                                           celltype.col = "LabeledCellType", 
                                           group.by = "segment")
## Warning in create_profile_matrix(mtx = ref.mtx, cellAnnots = ref.annot, : not
## all cellNameCol names are in count matrix; 5311 cells are missing
## [1] "Creating Atlas"
## [1] "1 / 21 : cTEC"
## [1] "2 / 21 : cTEC(cycling)"
## [1] "3 / 21 : mTEC_I"
## [1] "4 / 21 : mTEC_II"
## [1] "5 / 21 : TEC_Cldn10"
## [1] "6 / 21 : Epi(lung)"
## [1] "7 / 21 : muscle"
## [1] "8 / 21 : Fb_Postn"
## [1] "9 / 21 : mTEC_III"
## [1] "10 / 21 : Immune"
## [1] "11 / 21 : TEC(neuro)_like_1"
## [1] "12 / 21 : mTEC_IV(tuft)"
## [1] "13 / 21 : Fb_Aldh1a2"
## [1] "14 / 21 : Fb_Pi16"
## [1] "15 / 21 : Endo"
## [1] "16 / 21 : Mac"
## [1] "17 / 21 : TEC(neuro)_like_2"
## [1] "18 / 21 : Epi_Gcm2"
## [1] "19 / 21 : VSMC"
## [1] "20 / 21 : Epi_PAX8"
## [1] "21 / 21 : Ery"
## Using celltype as id variables
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
    print(spatial.output$figures)
## $abundance.heatmap

## 
## $cell.profile.heatmap

## 
## $composition.barplot

    print("Spatial Deconvolution Done")
## [1] "Spatial Deconvolution Done"